﻿#if __ANDROID__
using Android.App;
using Android.Content;
using System;
using System.Threading.Tasks;

using Outcoder.Concurrency;

namespace Outcoder.LauncherModel.Launchers
{
	public class ShareLinkLauncher : LauncherBase, IShareLinkLauncher
	{
		Uri linkUri;

		public Uri LinkUri
		{
			get
			{
				return linkUri;
			}
			set
			{
				linkUri = value;
			}
		}

		string message;

		public string Description
		{
			get
			{
				return message;
			}
			set
			{
				message = value;
			}
		}

		string title;

		public string Title
		{
			get
			{
				return title;
			}
			set
			{
				title = value;
			}
		}

		public override Task<bool> ShowAsync()
		{
			try
			{
				Intent intent = new Intent(Intent.ActionSend);
				intent.SetType("text/plain");
				intent.PutExtra(Intent.ExtraText, linkUri.ToString());
				intent.PutExtra(Intent.ExtraSubject, title);
				var chooser = Intent.CreateChooser(intent, "Share");

				var context = Dependency.Resolve<Context>();
				context.StartActivity(chooser);
			}
			catch (Exception ex)
			{
				return TaskUtility.FromException<bool>(ex);
			}

			return Task.FromResult(true);
		}
	}
}
#endif